<?php
namespace app\admin\controller;

use app\admin\my\MyPage;
use app\admin\my\MyConfig;

class Rob extends Base{

    private $type=['text'=>'文本回复','news'=>'图文回复','more'=>'多条回复'];
    public function rob() {
        $my = new MyPage();
       
        $my ->title("微信公众号管理")
            ->suggest("微信公众号列表")
            ->buttonNew("weEdit")
            ->setDb('rob')
            ->keyId()
            ->keyText('title', '名称')
            ->keyText('description', '简介')
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称', '微信公众号昵称')
             ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'rob');
        } else {
            return $my->fetch();
        }
    }



    public function robEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('rob/rob')->editData();
            if ($res>0) $this->success('更新成功','rob');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('rob/rob',$id);

            $my = new MyConfig();
            return  $my->title("编辑机器人")->keyId()
                        ->keyText('title', '名称')
                        ->keyText('description', '简介')
                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }



    public function app() {
        $my = new MyPage();
       
        $my ->title("微信公众号管理")
            ->suggest("微信公众号列表")
            ->buttonNew("appEdit")
            ->setDb('RobApp')
            ->keyId()
            ->keyText('title', '名称')
            ->keyText('description', '描述')
            ->keyText('keyword', '关键词')
            ->keyText('model_name', '应用标示')
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称')
             ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'RobApp');
        } else {
            return $my->fetch();
        }
    }



    public function appEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('rob/RobApp')->editData();
            if ($res>0) $this->success('更新成功','app');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('rob/RobApp',$id);

            $my = new MyConfig();
            return  $my->title("编辑应用")->keyId()
                        ->keyText('title', '名称')
                        ->keyText('description', '简介')
                        ->keyText('keyword', '关键词')
                        ->keyText('model_name', '应用标示')
                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }



     public function answer() {
        $my = new MyPage();
       
        $my ->title("问答管理")
            ->suggest("每一次问答都是一次服务——张小龙")
            ->buttonNew(url("answerEdit",['type'=>'text']),'文本消息')
            ->buttonNew(url("answerEdit",['type'=>'news']),'图文消息')
            ->buttonNew(url("answerEdit",['type'=>'more']),'文本消息')
            ->buttonNew("answerEdit")
            ->setDb('RobAnswer')
            ->keyId()
            ->keyText('title', '名称')
            ->keyText('description', '简介')
            ->keyText('keyword', '关键词')
            ->keyJoin('rob', '机器人', 'id', 'title', 'rob')
            ->keyMap('type','回复类型',$this->type)
            ->keyText('message', '文本回复')
            ->keyCreateTime()
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称')
            ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'RobAnswer');
        } else {
            return $my->fetch();
        }
    }



    public function answerEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('rob/RobAnswer')->editData();
            if ($res>0) $this->success('更新成功','answer');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('rob/RobAnswer',$id);

            $my = new MyConfig();
            return  $my->title("编辑机器人")->keyId()
                        ->keyText('title', '名称')
                        ->keyText('description', '简介')
                        ->keyText('keyword', '关键词')
                        ->keySelect('type', '类型','','',$this->type)
                        ->keyText('message', 'message')
                        ->keySelect('for_sex', '可见性别','','',['所有','男','女'])

                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }

    public function news() {
        $my = new MyPage();
       
        $my ->title("图文素材库")
            ->suggest("每一个十万加都是每一个对细节的苛刻")
            ->buttonNew("newsEdit")
            ->setDb('RobNews')
            ->keyId()
            ->keyText('title', '标题')
            ->keyText('description', '描述')
            ->keyText('url', '外部链接')
            ->keyText('picurl', '小图片')
            ->keyText('picurl_big', '大图片')
            
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称')
            ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'RobNews');
        } else {
            return $my->fetch();
        }
    }



    public function newsEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('rob/RobNews')->editData();
            if ($res>0) $this->success('更新成功','news');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('rob/RobNews',$id);

            $my = new MyConfig();
            return  $my->title("编辑机器人")->keyId()
                        ->keyText('title', '标题')
                        ->keyText('description', '描述')
                        ->keyText('url', '外部链接')
                        ->keyImage('picurl', '小图片')
                        ->keyImage('picurl_big', '大图片')
                        ->keyEditor('content', '正文')
                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }

    public function more() {
        $my = new MyPage();
       
        $my ->title("图文素材库")
            ->suggest("每一个十万加都是每一个对细节的苛刻")
            ->buttonNew("newsEdit")
            ->setDb('RobMore')
            ->keyId()
            ->keyText('title', '标题')
            ->keyText('description', '描述')
            ->keyText('answers', '回答集合')
            ->keyMap('type', '类型',['随机','追加'])
            
            
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称')
            ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'RobMore');
        } else {
            return $my->fetch();
        }
    }



    public function moreEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('Rob/RobMore')->editData();
            if ($res>0) $this->success('更新成功','more');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('Rob/RobMore',$id);

            $my = new MyConfig();
            return  $my->title("编辑机器人")->keyId()
                        ->keyText('title', '标题')
                        ->keyText('description', '描述')
                        ->keyText('answers', '回答集合')
                        ->keySelect('type', '类型','','',['随机','追加'])
                       
                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }

     public function media() {
        $my = new MyPage();
       
        $my ->title("图文素材库")
            ->suggest("每一个十万加都是每一个对细节的苛刻")
            ->buttonNew("mediaEdit")
            ->setDb('RobMedia')
            ->keyId()
            ->keyText('title', '标题')
            ->keyText('description', '描述')
            ->keyText('media_id', 'media_id')
           
            
            
            ->actionEdit()
            ->actionStatus('delete,disable')
            ->map('title', '名称')
            ->mapStatus();

        if ( request()->isAjax() ) {
            return myData($my,'RobMedia');
        } else {
            return $my->fetch();
        }
    }



    public function mediaEdit($id=0) {
        
        if ( request()->isPost() ) { 

            $res = model('Rob/RobMedia')->editData();
            if ($res>0) $this->success('更新成功','more');
            $this->error('更新失败');
        } else {
            
            $data=myEdit('Rob/RobMedia',$id);

            $my = new MyConfig();
            return  $my->title("编辑机器人")->keyId()
                        ->keyText('title', '标题')
                        ->keyText('description', '描述')
                        ->keyText('media_id', 'media_id')
                       
                        
                        ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
        }
    }


    
   

  

}